#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e3+100;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
char col[maxn];
LL dp[maxn][maxn];
int main(void){
   LL n;cin>>n;
   cin>>(col+1);
   memset(dp,0x3f,sizeof(dp));
   for(LL i=1;i<=n;i++) dp[i][i]=1;
   for(LL len=2;len<=n;len++){
       for(LL i=1;i+len-1<=n;i++){
           LL l=i;LL r=i+len-1;
           if(col[l]==col[l+1]){
              dp[l][r]=min(dp[l][r],dp[l+1][r]);
           }
           if(col[r]==col[r-1]){
              dp[l][r]=min(dp[l][r],dp[l][r-1]);
           }
           if(col[l]==col[r]){
              dp[l][r]=min(dp[l][r],min(dp[l+1][r],dp[l][r-1]));
           }
           for(LL k=l;k<=r;k++){
              dp[l][r]=min(dp[l][r],dp[l][k]+dp[k+1][r]);
           }
       }
   }
   cout<<dp[1][n]<<"\n";
   return 0;
}
